import 'package:dio/dio.dart';
/**
 *
 * onPressed: () {
    Navigator.of(context)
    .push(new MaterialPageRoute(builder: (_) {
    return new Browser(
    url: "https://flutter-io.cn/",
    title: "Flutter 中文社区",
    );
    }));
    }
 *
 */

import 'package:flutter/material.dart';
import 'package:village_android/component/jd_button.dart';
import 'package:village_android/utils/common_utils.dart';
import 'package:village_android/utils/http_utlis.dart';
import 'package:webview_flutter/webview_flutter.dart';

class MonitorAppealBrowserPage extends StatelessWidget {
  const MonitorAppealBrowserPage({Key key, this.url, this.title,this.healthReportId}) : super(key: key);

  final String url;
  final String title;
  final int healthReportId;


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: WebView(
        initialUrl: url,
        javascriptMode: JavascriptMode.unrestricted,
      ),
      bottomNavigationBar: initBottom(context),
    );
  }

  Widget initBottom(BuildContext context) {
    return BottomAppBar(
        child: Row(
          children: <Widget>[
            Expanded(
                child: JdButton(
                  callBack: () {

                    _asyncInputDialog(context,"");
                    },
                  text: "点击填写申诉",
                  color: Colors.red,
                )),
          ],
        ));
  }

  void submit(content,context){
    FormData formData = new FormData.from({
      "content": content,
      "healthReportId": healthReportId
    });
    HttpUtils.postForm("/api/healthReportAppeal/addItem", formData: formData, success: (data) {
      CommonUtils.showToast(context, "增加成功");
    }, error: (errorMsg) {
      CommonUtils.showToast(context, errorMsg);
    });
  }

  //弹出输入框
  Future<String> _asyncInputDialog(BuildContext context, initValue) async {
    String teamName = initValue;
    return showDialog<String>(
      context: context,
      barrierDismissible: false,
      // dialog is dismissible with a tap on the barrier
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('输入申诉理由'),
          content: new Row(
            children: <Widget>[
              new Expanded(
                  child: new TextField(
                    controller: TextEditingController()..text = teamName,
                    autofocus: true,
                    decoration:
                    new InputDecoration(labelText: '申诉理由', hintText: '如：申诉理由'),
                    onChanged: (value) {
                      teamName = value;
                    },
                  ))
            ],
          ),
          actions: <Widget>[
            new FlatButton(
              child: new Text("取消"),
              onPressed: () {
                Navigator.of(context).pop(initValue);
              },
            ),
            FlatButton(
              child: Text('确定'),
              onPressed: () {
                if (teamName.length == 0) {
                  CommonUtils.showToast(context, "不要输入空白");
                  return;
                }
                Navigator.of(context).pop("confirm");
                var appealContent = teamName;
                submit(appealContent, context);

                //请求
              },
            ),
          ],
        );
      },
    );
  }
}